package org.uni.cil.tester;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.uni.cil.mail.MailGetter;

public class TestCase {
	public static enum mailProvider {
		GMAIL_1000, GMAIL_5000, GMAIL_10000, STRATO, DOMAINFACTORY
	};
	
	public static enum crmProvider {
		CASPIA, SUGARCRM, SALESFORCE
	};
	
	private static Map<TestCase.mailProvider, String> username = Collections.unmodifiableMap( 
			new HashMap<TestCase.mailProvider, String> () {
			/**
				 *  
				 */
				private static final long serialVersionUID = 1L;

			{ 	put(TestCase.mailProvider.GMAIL_1000, "cilmail2crm@gmail.com");
				put(TestCase.mailProvider.GMAIL_5000, "cilmail2crmmedium@gmail.com");
				put(TestCase.mailProvider.GMAIL_10000, "cilmail2crmlarge@gmail.com");
				put (TestCase.mailProvider.STRATO, "crmcil@audriga-test.de");
				put (TestCase.mailProvider.DOMAINFACTORY, "crmcil@audriga.i24.cc");
			}
			});
	
	private static Map<TestCase.mailProvider, String> hostname = Collections.unmodifiableMap( 
			new HashMap<TestCase.mailProvider, String> () {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			{ 	put(TestCase.mailProvider.GMAIL_1000, "imap.gmail.com");
				put(TestCase.mailProvider.GMAIL_5000, "imap.gmail.com");
				put(TestCase.mailProvider.GMAIL_10000, "imap.gmail.com");
				put (TestCase.mailProvider.STRATO, "imap.strato.de");
				put (TestCase.mailProvider.DOMAINFACTORY, "sslmailpool.ispgateway.de");
			}
			});
	
	private static Map<TestCase.mailProvider, String> password = Collections.unmodifiableMap( 
			new HashMap<TestCase.mailProvider, String> () {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			{ 	put(TestCase.mailProvider.GMAIL_1000, "mail2crm");
				put(TestCase.mailProvider.GMAIL_5000, "mail2crm");	
				put(TestCase.mailProvider.GMAIL_10000, "mail2crm");
				put (TestCase.mailProvider.STRATO, "student@kit");
				put (TestCase.mailProvider.DOMAINFACTORY, "student@kit.edu");
			}
			});
	
	private static Map<TestCase.mailProvider, String> hosttype = Collections.unmodifiableMap( 
			new HashMap<TestCase.mailProvider, String> () {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			{ 	put(TestCase.mailProvider.GMAIL_1000, "imap");
				put(TestCase.mailProvider.GMAIL_5000, "imap");
				put(TestCase.mailProvider.GMAIL_10000, "imap");
				put (TestCase.mailProvider.STRATO, "imap");
				put (TestCase.mailProvider.DOMAINFACTORY, "imap");
			}
			});
	
	private static Map<TestCase.crmProvider, String> crmIp = Collections.unmodifiableMap( 
			new HashMap<TestCase.crmProvider, String> () {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			{ 	put(TestCase.crmProvider.CASPIA, "piademos.cas.de");
				put (TestCase.crmProvider.SALESFORCE, "");
				put (TestCase.crmProvider.SUGARCRM, "");
			}
			});
	
	private static Map<TestCase.mailProvider, String> mailIp = Collections.unmodifiableMap( 
			new HashMap<TestCase.mailProvider, String> () {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			{ 	put(TestCase.mailProvider.GMAIL_1000, "imap.gmail.com");
				put(TestCase.mailProvider.GMAIL_5000, "imap.gmail.com");
				put(TestCase.mailProvider.GMAIL_10000, "imap.gmail.com");
				put (TestCase.mailProvider.STRATO, "imap.strato.de");
				put (TestCase.mailProvider.DOMAINFACTORY, "sslmailpool.ispgateway.de");
			}
			});
	
	private static Map<TestCase.mailProvider, Boolean> sslMap = Collections.unmodifiableMap( 
			new HashMap<TestCase.mailProvider, Boolean> () {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			{ 	put(TestCase.mailProvider.GMAIL_1000, false);
				put(TestCase.mailProvider.GMAIL_5000, false);
				put(TestCase.mailProvider.GMAIL_10000, false);
				put (TestCase.mailProvider.STRATO, false);
				put (TestCase.mailProvider.DOMAINFACTORY, true);
			}
			});
	
	
	// Public members
	public HashMap<String, String> mailConnectionData;
	public TestCase.mailProvider email;
	public TestCase.crmProvider crm;
	public String crmProviderIp;
	public String mailProviderIp;
	public String[] searchTokens;
	public String[] searchValues;
	public boolean useSSL;
	
	public TestCase (TestCase.mailProvider mailProvider, TestCase.crmProvider crmProvider, boolean addSearch) {
		// Set crm and mail provider
		this.email = mailProvider;
		this.crm = crmProvider;
		this.crmProviderIp = TestCase.crmIp.get(crmProvider);
		this.mailProviderIp = TestCase.mailIp.get(mailProvider);
		
		// Get connection data for mail account
		this.mailConnectionData = new HashMap<String, String>();
		this.mailConnectionData.put("username", TestCase.username.get(mailProvider));
		this.mailConnectionData.put("password", TestCase.password.get(mailProvider));
		this.mailConnectionData.put("hostname", TestCase.hostname.get(mailProvider));
		this.mailConnectionData.put("hosttype", TestCase.hosttype.get(mailProvider));		
		
		// Add a simple search term if required
		if (addSearch)
		{
			// For testing first, test cases have to be specifieds
			this.searchTokens = new String[] {"FROM"};
			this.searchValues = new String[] {"google"};
		}
		else
		{
			this.searchTokens = new String[] {""};
			this.searchValues = new String[] {""};
		}
		this.useSSL = TestCase.sslMap.get(mailProvider);
	}
	
	public TestCase (HashMap<String, String> connectionData, TestCase.crmProvider crmProvider, boolean addSearch, boolean useSSL) {
		// Set crm and mail provider
		
		this.crm = crmProvider;
		this.crmProviderIp = TestCase.crmIp.get(crmProvider);
		this.mailProviderIp = connectionData.get("hostname");
		
		// Get connection data for mail account
		this.mailConnectionData = connectionData;
		
		// Add a simple search term if required
		if (addSearch)
		{
			// For testing first, test cases have to be specifieds
			this.searchTokens = new String[] {"FROM"};
			this.searchValues = new String[] {"google"};
		}
		else
		{
			this.searchTokens = new String[] {""};
			this.searchValues = new String[] {""};
		}
		if (useSSL){
			this.useSSL = true;
		}
		else {
			this.useSSL = false;
		}
	}
	
	public void setSearch (String[] searchTokens, String[] searchValues) {
		this.searchTokens = searchTokens;
		this.searchValues = searchValues;
	}
	
	public String toString(){
		String str = this.mailProviderIp.toString() + "-" + this.crmIp.toString();
		if (this.searchTokens.length > 0) {
			str = str + ";Search: " + this.searchTokens + this.searchValues;
		}
		else
		{
			str = str + ";Search: NoSearch";
		}
		return str;
	}
}
